
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Abahe
 */
public class MenuCanvas extends GameCanvas implements Runnable {

    LatihanMIDlet midlet;
    private boolean running = false;
    private Thread thread = null;
    private int speedGame = 30;
    private boolean isPaused = false;

    public MenuCanvas(LatihanMIDlet midlet) {
        super(false);
        setFullScreenMode(true);
        this.midlet = midlet;

    }

    private void drawDisplay(Graphics g) {
        g.setColor(0xffffff);
        g.drawRect(100, 100, getWidth(), getHeight());
        g.setColor(0x0000ff);
        g.drawString("Latihan J2ME", 0, 0, Graphics.TOP | Graphics.LEFT);
    }

    public void run() {
        Graphics g = getGraphics();
        while (running) {
            drawDisplay(g);
            try {
                Thread.sleep(speedGame);
            } catch (InterruptedException ie) {
            }
        }
    }

    public void start() {
        running = true;
        thread = new Thread(this);
        thread.start();
    }

    public void stop() {
    }

    protected void keyPressed(int keyCode) {
        if(keyCode == -7){
            midlet.exit();
        }
    }
}
